<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //产品表
        Schema::create('products', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('category_id')->comment('类别id');
            $table->string('name', 60)->comment('产品名字');
            $table->string('cover')->nullable()->comment('封面');
            $table->string('press', 60)->comment('出版社');
            $table->string('details')->comment('书籍参数');
            $table->timestamps();
        });

        //类别表
        Schema::create('categorys', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->comment('类别名');
            $table->integer('p_id')->comment('父级id')->default(0);
            $table->integer('level')->default(1)->comment('级别');
            $table->integer('sort')->nullable()->comment('排序');
            $table->timestamps();
        });

        //资源表
        Schema::create('resources', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->comment('资源名');
            $table->string('icon_url')->nullable()->comment('图标链接');
            $table->enum('status', ['enabled', 'disabled'])->default('enabled')->comment('状态');
            $table->integer('admin_id')->comment('操作管理员id');
            $table->timestamps();
        });

        //产品资源关联表
        Schema::create('product_resources', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('product_id')->comment('产品id');
            $table->integer('resource_id')->comment('类别id');
        });

        //产品图片关联表
        Schema::create('product_images', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('product_id')->comment('产品id');
            $table->integer('image_id')->comment('图片id');
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('products');
        Schema::drop('categorys');
        Schema::drop('resources');
        Schema::drop('product_resources');
        Schema::drop('product_images');
    }
}
